package com.gitee.wsl.mathematics.geometry.d2.contour

import com.gitee.wsl.mathematics.geometry.d2.contour.ext.difference
import com.gitee.wsl.mathematics.geometry.d2.contour.ext.intersection
import com.gitee.wsl.mathematics.geometry.d2.contour.ext.intersections
import com.gitee.wsl.mathematics.geometry.d2.contour.ext.union
import com.gitee.wsl.mathematics.geometry.d2.contour.segment.Segment2D
import com.gitee.wsl.mathematics.vector.vec2.Vec2f

/** Applies a boolean org.openrndr.shape.union operation between two [ContourShape]s. */
fun ContourShape.union(other: ContourShape): ContourShape = union(this, other)

/** Applies a boolean difference operation between two [ContourShape]s. */
fun ContourShape.difference(other: ContourShape): ContourShape = difference(this, other)

/** Applies a boolean intersection operation between two [ContourShape]s. */
fun ContourShape.intersection(other: ContourShape): ContourShape = intersection(this, other)

/** Calculates a [List] of all points where two [ContourShape]s intersect. */
fun ContourShape.intersections(other: ContourShape) = intersections(this, other)

/** Calculates a [List] of all points where the [ContourShape] and a [ShapeContour] intersect. */
fun ContourShape.intersections(other: ShapeContour) = intersections(this, other.shape)

/** Calculates a [List] of all points where the [ContourShape] and a [Segment2D] intersect. */
fun ContourShape.intersections(other: Segment2D) = intersections(this, other.contour.shape)

/** Returns true if given [Vector2] is inside the [ContourShape]. */
operator fun ContourShape.contains(v: Vec2f): Boolean {
    if (empty) {
        return false
    }
    return region2.contains(Vec2f(v.x, v.y))
}
